package cn.learn.server;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class NodeHashMapImpl implements NodeHashMap {
    private final ConcurrentHashMap<String, DataNode> nodes;

    public NodeHashMapImpl(){
        nodes = new ConcurrentHashMap<>();

    }

    @Override
    public DataNode put(String path, DataNode node) {
        DataNode oldNode = nodes.put(path, node);
        /*addDigest(path, node);
        if (oldNode != null) {
            removeDigest(path, oldNode);
        }*/
        return oldNode;
    }

    @Override
    public DataNode putWithoutDigest(String path, DataNode node) {
        return nodes.put(path, node);
    }

    @Override
    public DataNode get(String path) {
        return nodes.get(path);
    }

    @Override
    public void clear() {
        nodes.clear();
//        hash.clear();
    }

    @Override
    public Iterable<? extends Map.Entry<String, DataNode>> entrySet() {
        return nodes.entrySet();
    }
}
